package com.ruoyi.know.mapper;

import java.util.List;
import com.ruoyi.know.domain.KnowledgePoints;
import com.ruoyi.know.dto.TopKnowledgePointsDto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 知识点Mapper接口
 *
 * @author ruoyi
 * @date 2025-01-26
 */
public interface KnowledgePointsMapper
{
    /**
     * 查询知识点
     *
     * @param knowledgePointId 知识点主键
     * @return 知识点
     */
    public KnowledgePoints selectKnowledgePointsByKnowledgePointId(Long knowledgePointId);

    /**
     * 查询知识点列表
     *
     * @param knowledgePoints 知识点
     * @return 知识点集合
     */
    public List<KnowledgePoints> selectKnowledgePointsList(KnowledgePoints knowledgePoints);

    public List<KnowledgePoints> selectKnowledgePointsListByChapterId(Long chapterId);

    /**
     * 新增知识点
     *
     * @param knowledgePoints 知识点
     * @return 结果
     */
    public int insertKnowledgePoints(KnowledgePoints knowledgePoints);

    /**
     * 修改知识点
     *
     * @param knowledgePoints 知识点
     * @return 结果
     */
    public int updateKnowledgePoints(KnowledgePoints knowledgePoints);

    /**
     * 删除知识点
     *
     * @param knowledgePointId 知识点主键
     * @return 结果
     */
    public int deleteKnowledgePointsByKnowledgePointId(Long knowledgePointId);

    /**
     * 批量删除知识点
     *
     * @param knowledgePointIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteKnowledgePointsByKnowledgePointIds(Long[] knowledgePointIds);

    /**
     * 获取知识点总数量
     * @return
     */
    public int getKnowledgePointCount();

    /**
     * 查询浏览量前五的知识点
     * @return 包含id、名称、浏览量的Top5列表
     */
    @Select("SELECT knowledge_point_id as knowledgePointId, knowledge_point_name as knowledgePointName, visit_quantity as visitQuantity " +
            "FROM knowledge_points " +
            "WHERE is_valid = 1 " +
            "ORDER BY visit_quantity DESC " +
            "LIMIT 5")
    List<TopKnowledgePointsDto> selectTop5PointsByVisit();

    int setUrlToNull(@Param("type") Integer type, @Param("knowledgePointId") Long knowledgePointId);
}
